﻿//********************************************************************************//
//创建日期：<创建日期，2016-10-31>
//创建作者：<郭登杰，guodengjie@shanghai3h.com>
//功能说明：来涵退款信息
//********************************************************************************//
using BLL;
using BLL.Access;
using Entity;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Web.Class;
using Web.Controls.LAIHAN;

namespace Web.Controls
{
    public partial class UCLHTuiKuanInfoQS : System.Web.UI.UserControl, IUCLHOperate
    {
        #region 属性

        /// <summary>
        /// 来函类型
        /// </summary>
        public eLaiHanLX LaiHanLX
        {
            get;
            set;
        }

        /// <summary>
        /// 当前流程
        /// </summary>
        public eLaiHanLCBH LaiHanLC
        {
            get;
            set;
        }

        #endregion

        #region 变量

        #endregion

        #region 事件

        /// <summary>
        /// 加载事件
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitControl();
            }
        }

        /// <summary>
        /// 回调响应
        /// </summary>
        protected void ASPxCallback1_Callback(object source, DevExpress.Web.CallbackEventArgs e)
        {
            CallbackResult cr = new CallbackResult(e.Parameter);
            if (e.Parameter == "bh")//响应编号回车事件
            {
                DataRowCollection drc = new QS_YG_YONGHUXXProcess().SelectQS_YG_YONGHUXXesDynamic("I_JLZT=0 AND S_YONGHUH='" + this.txtYongHuH.Text + "'", null).Rows;
                if (drc.Count == 0)
                {
                    cr.IsSuccess = false;
                    cr.IsAlertMsg = true;
                    cr.Msg = "未查到对应的用户。";
                    e.Result = cr.ToString();
                }
                else
                {
                    cr.IsSuccess = true;
                    cr.IsAlertMsg = false;
                    cr.AddValue(Convert.ToString(drc[0]["S_YONGHUM"]));
                    e.Result = cr.ToString();
                }
            }
            else if(e.Parameter == "bh2")//响应水量年月回车事件
            {
                DataRowCollection drc = new SpHelper().P_QSLH_SFXXHQ(null,BusinessTool.WType,this.txtYongHuH.Text,int.Parse(this.txtYM.Text),Convert.ToInt32(this.cmbFeeType.Value)).Tables[0].Rows;
                if (drc.Count == 0)
                {
                    cr.IsSuccess = false;
                    cr.IsAlertMsg = true;
                    cr.Msg = "无对应收费记录";
                }
                else
                {
                    DataRow dr = drc[0];
                    cr.IsSuccess = true;
                    cr.IsAlertMsg = false;
                    cr.AddValue(Convert.ToString(dr["N_YSJE"]), Convert.ToString(dr["N_SSJE"]), Convert.ToString(dr["S_ZHANGDANBH"]));
                }
                e.Result = cr.ToString();
            }
        }

        /// <summary>
        /// 前台验证后实际执行后台操作
        /// </summary>
        protected void btnActPerform_Click(object sender, EventArgs e)
        {
        }

        #endregion

        #region 方法

        /// <summary>
        /// 配置控件
        /// </summary>
        public void InitControl()
        {
            PageTools.QSLoadCombox(this.cmbFeeType,PageTools.eLoadType.费用类型QS,null,"");
            PageTools.QSLoadCombox(this.cmbTuiKuanLX, PageTools.eLoadType.退款类型QS, null, "");
            this.txtLaiHanBH.ClientEnabled = false;
            this.txtSSJE.ClientEnabled = false;
            this.txtTuiKuanJE.ClientEnabled = true;
            this.txtXuKeZH.ClientEnabled = false;
            this.txtYM.ClientEnabled = true;
            this.txtYongHuH.ClientEnabled = true;
            this.txtYongHuM.ClientEnabled = false;
            this.txtYSJE.ClientEnabled = false;
            this.cmbFeeType.ClientEnabled = true;
            this.cmbTuiKuanLX.ClientEnabled = true;
            this.cmbFeeType.SelectedIndex = 1;
            this.cmbTuiKuanLX.SelectedIndex = 1;
        }

        /// <summary>
        ///根据当前流程状态设置步骤显示
        /// </summary>
        private void SetDisplay()
        {
            //根据类型显示需要的             
            //受理之后不可编辑.下方switch中case 3可去除.使用此控件的受理之后的页面该控件属性需加上LaiHanLC="受理"
            if ((int)this.LaiHanLC <= (int)eLaiHanLCBH.预登记)
            {
                this.txtYongHuH.ClientEnabled = true;
                this.txtYM.ClientEnabled = true;
                this.txtTuiKuanJE.ClientEnabled = true;
                this.cmbFeeType.ClientEnabled = true;
                this.cmbTuiKuanLX.ClientEnabled = true;
            }
            else if ((int)this.LaiHanLC > (int)eLaiHanLCBH.预登记)
            {
                this.txtYongHuH.ClientEnabled = false;
                this.txtYM.ClientEnabled = false;
                this.txtTuiKuanJE.ClientEnabled = false;
                this.cmbFeeType.ClientEnabled = false;
                this.cmbTuiKuanLX.ClientEnabled = false;
            }
        }

        /// <summary>
        /// 验证数据
        /// </summary>
        public ValidateRS Validate()
        {
            ValidateRS rs = new ValidateRS();
            if (this.txtYongHuM.Text == "")
            {
                rs.Msg = "请查询出用户";
                return rs;
            }
            if (this.txtYM.Text == "")
            {
                rs.Msg = "请输入水量年月";
                return rs;
            }
            if (this.txtYSJE.Text == "")
            {
                rs.Msg = "请查询出收费信息";
                return rs;
            }
            if (this.cmbFeeType.Text == "")
            {
                rs.Msg = "请选择费用类型";
                return rs;
            }
            if (this.cmbTuiKuanLX.Text == "")
            {
                rs.Msg = "请选择退款类型";
                return rs;
            }
            if (this.txtTuiKuanJE.Text == "")
            {
                rs.Msg = "请填写退款金额";
                return rs;
            }
            if (!PageTools.ValidateString(this.txtTuiKuanJE.Text, PageTools.eValidateType.数字)||decimal.Parse(this.txtTuiKuanJE.Text)<=0)
            {
                rs.Msg = "请填写正确的退款金额";
                return rs;
            }
            rs.IsSuccess = true;
            return rs;
        }

        /// <summary>
        /// 清除数据
        /// </summary>
        public void ClearInfo()
        {
            this.txtFeiYongBH.Text = "";
            this.txtLaiHanBH.Text = "";
            this.txtSSJE.Text = "";
            this.txtTuiKuanJE.Text = "";
            this.txtXuKeZH.Text = "";
            this.txtYM.Text = "";
            this.txtYongHuH.Text = "";
            this.txtYongHuM.Text = "";
            this.txtYSJE.Text = "";
            this.cmbFeeType.Text = "";
            this.cmbTuiKuanLX.Text = "";
        }


        /// <summary>
        /// 根据来函加载信息
        /// </summary>
        public void LoadInfo(YS_LH_LAIHANXX laihanxx)
        {
            //登记前
            if (laihanxx.ID == 0)
            {
                this.LaiHanLC = eLaiHanLCBH.未登记;
                SetDisplay();
                return;
            }
            else
            {
                this.LaiHanLC = (eLaiHanLCBH)Enum.Parse(typeof(eLaiHanLCBH), laihanxx.I_LIUCHENGBH.ToString());
                SetDisplay();
            }
            this.txtLaiHanBH.Text = laihanxx.S_LAIHANBH;
            this.txtXuKeZH.Text = laihanxx.S_XUKEBH;
            DataRowCollection drc=new SpHelper().P_QSLH_SFXXHQ(laihanxx.S_LAIHANBH, BusinessTool.WType, null, null, null).Tables[0].Rows;
            if (drc.Count > 0)
            {
                DataRow dr = drc[0];
                this.txtFeiYongBH.Text = Convert.ToString(dr["S_FEIYONGBH"]);
                this.txtSSJE.Text = Convert.ToString(dr["N_SSJE"]);
                this.txtTuiKuanJE.Text = Convert.ToString(dr["N_TKJE"]);
                this.txtYM.Text = Convert.ToString(dr["I_YM"]);
                this.txtYongHuH.Text = Convert.ToString(dr["S_YONGHUH"]);
                this.txtYongHuM.Text = Convert.ToString(dr["S_YONGHUM"]);
                this.txtYSJE.Text = Convert.ToString(dr["N_YSJE"]);
                this.cmbFeeType.Value = Convert.ToString(dr["I_FEETYPE"]);
                this.cmbTuiKuanLX.Value = Convert.ToString(dr["I_TKTYPE"]);
            }
        }

        /// <summary>
        /// 获取来函主表信息
        /// </summary>
        /// <param name="laihanid">ID</param>
        /// <param name="liuchengzt">0:收件 1:收件并登记</param>
        /// <param name="msg">输出消息,正常为空</param>
        /// <returns>null:验证失败 !null:成功返回</returns>
        public YS_LH_LAIHANXX GetLAIHANXX(int laihanid, int liuchengzt, out string msg)
        {
            YS_LH_LAIHANXX laihan = new YS_LH_LAIHANXX();
            string laihanbh = "";
            string xukebh = "";
            msg = "";
            laihan.ID = laihanid;
            if (laihanid == 0)
            {
                string zd, glk, ywy;
                PageTools.GetLHDJZDGLKYWY(this.txtYongHuH.Text, out zd, out glk, out ywy);
                laihan.S_ZHANDIANBH = zd;
                laihan.S_GUANLIKBH = glk;
                laihan.I_YWY = int.Parse(ywy);
                laihan.S_YWY = BusinessTool.GetYWYName(ywy);
                //laihan.S_YHYWY = ywy;
                DataSet numset = new SpHelper().P_YS_LH_XUKEBH(glk, (int)this.LaiHanLX, 0, (BusinessTool.GetWaterYM() / 100).ToString(), out xukebh, out laihanbh);
                //DataSet numset = new SpHelper().P_YS_LH_XUKEBH(BusinessTool.QSGLKH, 1, 0, (int.Parse(this.txtYM.Text) / 100).ToString(), out xukebh, out laihanbh);
                new SpHelper().P_ALL_LH_BHSC(BusinessTool.WType, (int)this.LaiHanLX, BusinessTool.GetWaterYM() / 100, out laihanbh);
                laihan.I_XT = BusinessTool.WType;
                laihan.D_SHURURQ = DateTime.Now;
                laihan.D_LAIHANRQ = DateTime.Now;
                laihan.I_JLZT = 0;
                laihan.I_LAIHANLX = (int)this.LaiHanLX;
                laihan.I_SHURUR = LoginInfo.CurrentUser.UserID;
                laihan.I_AUTOTYPE = 0;
                laihan.S_LAIHANBH = laihanbh;
                laihan.S_BEIYONG1 = xukebh;
                laihan.S_XUKEBH = xukebh;
                laihan.I_LIUCHENGZT = (int)eLaiHanLCZT.流程中;
                laihan.S_YONGHUBH = this.txtYongHuH.Text;
                laihan.S_YONGHUM = this.txtYongHuM.Text;
                laihan.I_TZY = laihan.I_Y = int.Parse(this.txtYM.Text) / 100;
                laihan.I_TZM = laihan.I_M = int.Parse(this.txtYM.Text) % 100;
                //laihan.I_Y = BusinessTool.GetWaterYM() / 100;
                //laihan.I_M = BusinessTool.GetWaterYM() % 100;
            }
            else
            {
                laihan = new YS_LH_LAIHANXXProcess().SelectYS_LH_LAIHANXX(laihan.ID);
            }
            laihan.I_LIUCHENGBH = liuchengzt;
            laihan.S_CAOZUOR = LoginInfo.CurrentUser.UserID.ToString();
            laihan.D_CAOZUOSJ = BusinessTool.GetDataBaseDateTime();
            return laihan;
        }

        /// <summary>
        /// 获取来函用户信息
        /// </summary>
        /// <param name="laihan"></param>
        /// <returns></returns>
        public YS_LH_YONGHUXX GetLHYONGHUXX(YS_LH_LAIHANXX laihan)
        {
            return null;
        }

        /// <summary>
        /// 添加申请信息
        /// </summary>
        /// <param name="laihanxx"></param>
        public void CreateShengQingXX(YS_LH_LAIHANXX laihanxx)
        {
            //清除记录
            QS_LH_TUIKUANXXProcess bllT2 = new QS_LH_TUIKUANXXProcess();
            bllT2.DeleteQS_LH_TUIKUANXXesDynamic("S_LAIHANBH=" + laihanxx.S_LAIHANBH);
            //添加记录
            QS_LH_TUIKUANXX item = new QS_LH_TUIKUANXX();
            item.I_FEETYPE = Convert.ToInt32(this.cmbFeeType.Value);
            item.I_TKTYPE = Convert.ToInt32(this.cmbTuiKuanLX.Value);
            item.I_YM = Convert.ToInt32(this.txtYM.Text);
            item.N_SSJE = Convert.ToDecimal(this.txtSSJE.Text);
            item.N_TKJE = Convert.ToDecimal(this.txtTuiKuanJE.Text);
            item.N_YSJE = Convert.ToDecimal(this.txtYSJE.Text);
            item.S_FEIYONGBH = this.txtFeiYongBH.Text;
            item.S_LAIHANBH = laihanxx.S_LAIHANBH;
            item.S_YONGHUH = this.txtYongHuH.Text;
            item.S_YONGHUM = this.txtYongHuM.Text;
            item.D_CAOZUOSJ = BusinessTool.GetDataBaseDateTime();
            item.S_CAOZUOR = LoginInfo.CurrentUser.UserID.ToString();
            item.I_TUIKUANZT = 0;
            bllT2.InsertOrUpdate(item);
        }


        #endregion


    }
}